import request from '@/utils/Request.js'

/**
 * 用户登录接口
 * @param {Object} data 登录凭证 
 * @param {string} data.username 用户名
 * @param {string} data.password 密码
 * @returns {Promise} 包含用户信息的Promise
 */
export const loginApi = (data) => {
    return request.post('/login', data)
}

/**
 * 用户注册接口 
 * @param {Object} data 注册信息
 * @param {string} data.username 用户名（4-20位）
 * @param {string} data.password 密码（6-20位）
 * @param {string} data.email 邮箱
 * @returns {Promise} 包含注册结果的Promise
 */
export const registerApi = (data) => {
    return request.post('/register', {
        username: data.username,
        password: data.password,
        email: data.email,
        phone: data.phone,
    })
}

/**
 * 修改密码接口
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const updatePasswordApi = (data) => {
    return request.put('/updatePassword', {
        username: data.username,
        password: data.password,
        newPassword: data.newPassword,
        confirmPassword: data.confirmPassword,
    })
}

/**
 * 修改个人信息
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const updateInfoApi = (data) => {
    return request.put('/updateInfo', {
        "username": data.username,
        "email": data.email,
        "phone": data.phone,
        "storageQuota": data.storageQuota,
        "usedStorage": data.usedStorage,
        "avatar": data.avatar,
        "realName": data.realName,
    })
}
